package group9;


import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.google.appengine.api.datastore.Key;

/**
 * @author Claudio Herreros, Dylan James, Tyler Berg
 *
 */

@SuppressWarnings("serial")
public class EditUserStoryServlet extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
		
		UserStory userstory = (UserStory) req.getSession().getAttribute("UserStory");

		if (userstory == null)
		{
			resp.sendRedirect("MyUserStories.jsp");
		}
		
		String title = req.getParameter("title");
		String description = req.getParameter("description");
		String testNotes = req.getParameter("testnotes");
		
		User user = (User) req.getSession().getAttribute("User");

		PersistenceManager pm = PMF.get().getPersistenceManager();
		user = (User) pm.getObjectById(User.class, user.getKey());

		if (user == null)
		{
			resp.sendRedirect("index.html");
			return;
		}
		//database object
		UserStory userStory = (UserStory) pm.getObjectById(UserStory.class, userstory.getKey());
		userStory.setTitle(title);
		userStory.setDescription(description);
		userStory.setTestNotes(testNotes);
		
		//session attribute
		userstory.setTitle(title);
		userstory.setDescription(description);
		userstory.setTestNotes(testNotes);
		
		
		pm.close();
		
		
		resp.sendRedirect("MyUserStories.jsp");
	}
}